package app.controller.login;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import app.service.login.QrLoginService;
import base.JsonResult;


@Controller
@RequestMapping("/user/qrLogin")
public class QrLoginController {
	
	@Resource
	private QrLoginService qrLoginService;
	
	/**
	 * 前端生成二维码和登录id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/initQrLogin.do")
	public JsonResult initQrLogin(){
		return new JsonResult(qrLoginService.initQrLogin());
	}
	
	/**
	 * 前端等待终端扫描二维码
	 * @param loginId
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/waitingQrLogin.do")
	public JsonResult waitingQrLogin(String loginId){
		return new JsonResult(qrLoginService.waitingQrLogin(loginId));
	}
	
	/**
	 * 终端扫描二维码
	 * @param loginId
	 */
	@ResponseBody
	@RequestMapping(value = "/scanQrLogin.do" , method = { RequestMethod.POST })
	public JsonResult scanQrLogin(String loginId){
		qrLoginService.scanQrLogin(loginId);
		return new JsonResult("操作成功");
	}
	
	/**
	 * 终端确认二维码登录
	 * @param loginId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/confirmQrLogin.do" , method = { RequestMethod.POST })
	public JsonResult confirmQrLogin(String loginId){
		qrLoginService.confirmQrLogin(loginId);
		return new JsonResult("操作成功");
	}
}
